﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
using System.IO;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;

namespace SimpleDesktop
{
    [Serializable]
    public class PageModel
    {
        public string Name { get; set; }
        public List<string> Items { get; set; }
        public PageModel(string name)
        {
            Name = name;
            Items = new List<string>();
        }

        /**
         * 根据这个对象即可创建一个新的page了！
         */
        public void CreatePage(Form1 form)
        {
            ClassPage page = form.addPage(Name);
            foreach (string path in Items)
            {
                page.addPicture(path);
            }
        }
    }
    [Serializable]
    public class PageModels
    {
        public List<PageModel> Pages { get; set;}
        public PageModels()
        {
            Pages = new List<PageModel>();
        }
    }

    /**
     * 用于保存文件数据
     * 
     */
    public class FileSaver
    {
        public static readonly string filePath = "./config.json";
        public static void SerializeToFile(PageModels obj)
        {
            string jsonString = JsonSerializer.Serialize(obj);
            File.WriteAllText(filePath, jsonString);
        }

        public static PageModels DeserializeFromFile()
        {
            string jsonString = File.ReadAllText(filePath);
            return JsonSerializer.Deserialize<PageModels>(jsonString);
        }
    }
}
